package com.yurun.loginmodule.controller;

import com.github.pagehelper.PageHelper;
import com.yurun.commonapi.api.CommonResult;
import com.yurun.commonapi.pojo.Teacher;
import com.yurun.loginmodule.util.JWTUtil;
import com.yurun.teacherorgmodule.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletRequest;
import java.math.BigInteger;

@Api(tags = "教师模块")
@RestController
@RequestMapping("/teacherManage")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @ApiOperation(value = "根据条件查询教师信息")
    @RequiresPermissions("/allTeacherInfo")
    @RequestMapping("/allTeacherInfo")
    public CommonResult getAllTeacherList(ServletRequest request, String keyword, String branchId, String teamId, int pageNum, int pageSize){
        // 获取token
        String token = WebUtils.toHttp(request).getHeader("Authorization").substring(6);
        System.out.println(token);
        // 获取机构id
        String organizationId = JWTUtil.getOrganizationId(token);
        System.out.println("branchId");
        PageHelper.startPage(pageNum, pageSize);
        return teacherService.allTeacherInfo(keyword, BigInteger.valueOf(Long.parseLong(organizationId)), branchId, teamId);
    }

    @ApiOperation(value = "修改教师信息")
    @RequiresPermissions("/editTeacher")
    @RequestMapping("/editTeacher")
    public CommonResult editTeacher(Teacher teacher){
        return teacherService.editTeacher(teacher);
    }


}
